/*年轻人，只管向前看，不要管自暴自弃者的话*/
package com.composetest.page.splash

import android.os.CountDownTimer
import android.util.Log
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel


/**
 * create by itz on 2024/10/11 16:36
 * desc :
 **/
class SplashViewModel : ViewModel() {
    private var timer: CountDownTimer? = null
    var timeDown by mutableStateOf(0L)
    var navigationGuide by mutableStateOf(false)

    init {
        startCountDown()
    }

    private fun startCountDown() {
        timer = object : CountDownTimer(3000, 1000) {
            /**
             * 倒计时执行
             */
            override fun onTick(millisUntilFinished: Long) {
                timeDown = millisUntilFinished / 1000
                Log.e("SplashRoute", "timeDown $timeDown")
            }

            /**
             * 倒计时结束
             */
            override fun onFinish() {
                navigationGuide = true
            }

        }.start()
    }

    fun next(): Unit {
        timer?.cancel()
        navigationGuide = true
    }

    override fun onCleared() {
        super.onCleared()
        timer?.cancel()
    }
}